package com.twu.biblioteca.content;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by mduemcke on 9/25/14.
 */
public class BookContent extends ContentAbstract<Book>{

    public BookContent() {
        super();
    }

    public void checkoutItem(String title) {
        super.checkoutItem(title, "Thank you! Enjoy the book", "That book is not available.");
    }

    public  void returnItem(String title) {
        super.returnItem(title, "Thank you for returning the book.", "That is not a valid book to return.");
    }

    @Override
    protected void fillContent() {
        availableItems = new LinkedList<Book>();
        availableItems.add(new Book("Test Driven Development. By Example", "Kent Beck", 2002));
        availableItems.add(new Book("Extreme Programming Explained: Embrace Change", "Kent Beck", 2004));
    }

    @Override
    protected String listToString(List<Book> l) {
        String formatted = "%-50s|%-50s|%-10s|\n";
        String listAsString = String.format(formatted, "Title", "Author", "Year");

        for (Book b : l) {
            listAsString += String.format(formatted, b.title, b.author, Integer.toString(b.year));
        }
        return listAsString;
    }

    @Override
    protected int getIndexFromTitle(String title, List<Book> list) {
        for (int i = 0; i < list.size(); i++) {
            Book b = list.get(i);
            if (b.title.equals(title)) {
                return i;
            }
        }
        return -1;
    }

}
